import apiClient from '@/api/axios.js';

export class UserAddrApi {

  // 根据 userID 查询地址
  static async getUserAddressByUserId(userID) {
    try {
      const response = await apiClient.get(`/useraddr/${userID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 新增地址
  static async createUserAddress(params) {
    const { userID, address, phone, status } = params;
    try {
      const response = await apiClient.post('/useraddr', {
        userID,
        address,
        phone,
        status
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 更新地址
  static async updateUserAddress(addrID, params) {
    const { userID, address, phone, status } = params;
    try {
      const response = await apiClient.put(`/useraddr/${addrID}`, {
        addrID,
        userID,
        address,
        phone,
        status
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 删除地址
  static async deleteUserAddress(addrID) {
    try {
      const response = await apiClient.delete(`/useraddr/${addrID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }
}
